/**
 * Note: The returned array must be malloced, assume caller calls free().
 */



void ShellSort(int* a, int n)
{
	int gap = n;
	while (gap >= 1)
	{
		gap /= 2;

		for (int i = 0; i < n - gap; i++)
		{
			int end = i;
			int tmp = a[end + gap];
			while (end >= 0)
			{
				if (a[end] > tmp)
				{
					a[end + gap] = a[end];
					end -= gap;
				}
				else
				{
					break;
				}
			}
			a[end + gap] = tmp;
		}
	}
}

int* sortArray(int* nums, int numsSize, int* returnSize) {
	*returnSize = numsSize;
	ShellSort(nums, numsSize);

	return nums;
}